<h3>Assign group to a SYSTEM user</h3>
<span style="color:gray;font-size: 9px">** If you do not see your newly created group(s) please refresh the page!</span>
<table id="table" width="100%" >
    <thead>
        <tr>
            <th>User Name</th>
            <th>Email</th>
            <th>Assigned Group</th>
        </tr>
    </thead>
    <tbody>
        {{foreach from=$admin_users item=user}}
        <tr class="table_row">
            <td>
                <a href="#"  title="View user details" >{{$user->username}}</a>
            </td>
            <td >
                {{$user->email}}
            </td>
            <td>
                <select id="select_group" name="select_group" class="long" onchange="assign_group('{{$user->id}}',this)">
                    <option></option>
                    {{foreach from=$groups item=group}}
                    <option value="{{$group->id}}"
                            {{if $user->DYN_permission_group<>""}}
                              {{if $user->DYN_permission_group->id==$group->id}}
                                selected
                               {{/if}} {{/if}} >{{$group->name}}</option>
                    {{/foreach}}
                </select>
            </td>
        </tr>
        {{/foreach}}


</tbody>
</table>
<script type="text/javascript">
    function assign_group(uid,self){
        group_id =  self.options[self.selectedIndex].value;
        if(group_id && group_id.length){
            $.ajax({
                type:"POST",
                dataType:'text',
                data:"is_ajax=1&group_id="+group_id+"&user_id="+uid,
                url: module_admin_url+"/groups/assign_group",
                beforeSend: function(){
                     $.blockUI("<h1>Please wait...</h1>");
                },
                complete :  function(data){
                    $.unblockUI();
                }
            });
        }
    }
</script>